'use strict';

module.exports = app => {
    class SmsService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        async send(params) {
            /**
             * 请求后台接口
             */
            const result = await this.ctx.fetch(this.app.urls('sms', {}, this.config.api.im), {
                method: 'post',
                data: params,
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }

    }

    return SmsService;
};
